<?php 
/* SVN FILE: $Id: searchForm.ctp 39 2007-09-20 00:12:05Z joe.vasquez $ */
/**
 * element for rendering search forms
 * @filesource
 * @author			Joe Vasquez <joe.vasquez@gmail.com>
 * @copyright		Copyright (c) 2007, Joe Vasquez
 * @package			redlettr
 * @subpackage		elements
 * @since			0.1A
 * @version			0.1A  $Rev: 39 $
 * @lastmodified	$Date: 2007-09-20 00:12:05 +0000 (Thu, 20 Sep 2007) $
 * @license			http://www.gnu.org/licenses/gpl.html GNU General Public License
 */
?>
<div id="toggleControls"></div>
<?php $ids = array(); foreach($searchFields as $fieldName => $fieldOptions): ?>
<fieldset id="<?php echo $fieldOptions['id']; ?>_fieldset">
<legend><?php echo preg_replace('/\./',' ',$fieldName); ?></legend>
	<?php if(is_array($fieldOptions) && array_key_exists('options',$fieldOptions)): ?>
		<?php echo $form->input($fieldName,$fieldOptions['options']); ?>
	<?php else: ?>
		<?php echo $form->input($fieldName); ?>
	<?php endif; ?>
<?php echo $form->input(
	$fieldName.'_or',
	array(
		'type'		=> 'radio',
		'options'	=>	array('and','or'),
		'label'		=> 'Search Inclusion',
		'div'		=> 'searchInclusion',
		'class' 	=> 'radioInput'
	)
); ?>	
<?php echo $form->input(
	$fieldName.'_conditions',
	array(
		'type'		=> 'radio',
		'options'	=>	$fieldOptions['conditions'],
		'label'		=> 'Conditions',
		'div'		=> 'searchConditions',
		'class' 	=> 'radioInput'
	)
); ?>
</fieldset>
<?php $ids[] = $fieldOptions['id']; ?>
<?php endforeach; ?>
<fieldset id="Number_of_Records_fieldset">
<legend>Number of records to return</legend>
<?php echo $form->input(
	'number',
	array(
		'type'		=> 'radio',
		'options'	=>	array(
			'all','5','10','20','50','100'
		),
		'label'		=> 'Number',
		'div'		=> 'numberToReturn',
		'class' => 'radioInput'
	)
); ?>
</fieldset>
<?php $ids[] = 'Number_of_Records'; ?>
<script type="text/javascript">
$(document).ready(function(){
	$('div#toggleControls').append('<p><strong>Searable Fields:</strong> </p>');
<?php foreach($ids as $id): ?>
	var idStr = '<?php echo $id; ?>';
	$('div#toggleControls p').append('<a class="toggleField" href="#<?php echo $id; ?>_fieldset"><?php echo preg_replace('/_/',' ',$id); ?></a> ');
<?php endforeach; ?>
	$('fieldset').hide();
	$('a.toggleField').click(function(){
		var target = $(this).attr('href').substr(1);
		if($('fieldset#'+target).css('display') != 'none')
		{
			$('fieldset#'+target+' input').val('');
		}
		$('fieldset#'+target).slideToggle();
		$(this).toggleClass('ok');
		return false;
	});
});
</script>